
class Animal {
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat() {
        System.out.println(name + " 吃饭！");
    }
}

class Dog extends Animal {
    public void bark() {
        System.out.println(this.name + " 汪汪叫！");
    }

    @Override
    public void eat() {
        System.out.println(this.name + " 吃狗粮！");
    }

    public Dog(String name, int age) {
        super(name, age);
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

class Cat extends Animal {
    public void bark() {
        System.out.println(this.name + " 喵喵叫！");
    }
    @Override
    public void eat() {
        System.out.println(this.name + " 吃猫粮！");
    }

    public void mimi(){
        System.out.println(this.name+ " 喵喵叫");
    }

    public Cat(String name, int age) {
        super(name, age);
    }
}


public class Test {

    public static void main(String[] args) {
        Animal animal = new Dog("圆圆",19);
        /*//animal.bark();
        Dog dog = (Dog)animal;
        dog.bark();*/

        if(animal instanceof Cat){
            Cat cat = (Cat)animal;
            cat.mimi();
        }else {
            System.out.println("haha");
        }

    }

    public static void eatFunc(Animal animal){
        animal.eat();
    }

    public static void main4(String[] args) {
        Dog dog = new Dog("圆圆",19);
        Cat cat = new Cat("十二",23);

        eatFunc(dog);
        eatFunc(cat);
    }

    public static void main3(String[] args) {
        Animal animal1 = new Dog("圆圆",19);
        Animal animal2 = new Cat("十二",23);
        animal1.eat();
        animal2.eat();
    }


    public static void func1(Animal animal){

    }
    public static Animal func2() {
        Dog dog = new Dog("圆圆",19);
        return dog;
    }
    public static void main2(String[] args) {
        Dog dog = new Dog("圆圆",19);
        func1(dog);

        Animal dog2 = func2();
    }

    public static void main1(String[] args) {
        /*Dog dog = new Dog("圆圆",19);
        Animal animal = dog;*/

        Animal animal = new Dog("圆圆", 19);
        animal.eat();
    }
}

